home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17608 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.mathworks.com!gatech!psinntp!psinntp!psinntp!pipeline!not-for-mail
  2. From: gniemcew@nyc.pipeline.com (Gabriel Niemcewicz)
  3. Newsgroups: comp.lang.c++
  4. Subject: newbie help with 2-d arrays please ?
  5. Date: 16 Apr 1996 04:21:27 -0400
  6. Organization: Pipeline
  7. Message-ID: <4kvla7$516@pipe9.nyc.pipeline.com>
  8. X-PipeUser: gniemcew
  9. X-PipeHub: nyc.pipeline.com
  10. X-PipeGCOS: (Gary)
  11. X-Newsreader: Pipeline v3.5.0
  12.  
  13. Hi ! 
  14.  
  15. I am currently writing a project on graphs and I encountered something I
  16. cannot figure out when writing adjacency matrix representation: 
  17.  
  18. class graph { 
  19.  
  20.     int  size;        // number of vertices in a representation 
  21.     int  *array;        // ptr to the allocated 2-d array 
  22.  
  23. <snip> 
  24. }; 
  25.  
  26. And the following doesn't work: 
  27.  
  28. int 
  29. graph::add_vertex(int vertex_id) 
  30.     int* table; 
  31.     table = new int [temp_size][temp_size]; // this gives me errors about
  32. static declaration type required....? 
  33.  
  34. <snip> 
  35.                 table[i][j] = -1; 
  36.  
  37. <snip> 
  38.  
  39.                 table[i][j] = array[i][j]; 
  40.  
  41. <snip> 
  42.  
  43.         array=table;               // ini header value 
  44.  
  45. <snip> 
  46.  
  47.     array[vertex1-1][vertex2-1] = weight;        // store adjacency info 
  48.     array[vertex2-1][vertex1-1] = weight;        // update both links 
  49.  
  50. <snip> 
  51.  
  52.                 printf ("%3d", array[i][j]); 
  53.  
  54. I can't reference the array at all. I read two books on c++, but only 1-D
  55. arrays are discussed. 
  56. I bet the reason is some tricky pointer declaration, something like int*
  57. array[][], or something like that. 
  58. I need to allocate arrays dynamically because I am doing rehashing on them
  59. as new vertices are addded. 
  60.  
  61. Any suggestions ? I would appreciate some feedback. 
  62.  
  63. Please mail me at gniemcew@shiva.hunter.cuny.edu 
  64.  
  65. Thx, 
  66.  
  67. Gary 
  68.